﻿using System;
using Castle.DynamicProxy;
using RrslLite.Net.Messages;

namespace RrslLite.Net.Aop
{
    public class InterceptorAsync<TTarget> : InterceptorBase<TTarget>
    {
        public InterceptorAsync(Message message)
            : base(message)
        {
            if (message.CorrelationId == Guid.Empty)
            {
                throw new ArgumentException("Message instance must contain non-empty guid");
            }
        }

        protected override void ProcessMessage(Message message, IInvocation invocation)
        {
            Type returnValueType = invocation.Method.ReturnType;

            if (returnValueType.FullName == "System.Void")
            {
                return;
            }

            if (returnValueType.IsValueType)
            {
                invocation.ReturnValue = Activator.CreateInstance(returnValueType);
            }
        }
    }
}
